<template>
  <div class="tab-control">
    <div
      v-for="(item, index) in titles"
      :key="index"
      class="tab-control-item"
      :class="{ active: index === currentIndex }"
      @click="changeColor(index)">
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    changeColor(index) {
      this.currentIndex = index;
      this.$emit("tabClick", index);
    }
  },
};
</script>

<style scoped>
.tab-control {
  margin-top: 10px;
  display: flex;
  justify-content: space-around;
  text-align: center;
  height: 40px;
  line-height: 40px;
  font-size: 14px;
  z-index: 999;
  position: sticky;
  top: 45px;
  background-color: #fff;
}

.tab-control-item {
  width: 65px;
}

.active {
  color: #ff5777;
  border-bottom: #ee0a24 solid 3px;
}
</style>